package com.mingda.weathermagiccenter.utils;


import java.text.DecimalFormat;

/**
 * //TODO UV数据与风速风向数据转换
 */
public class UVAndSD {

    /**
     * UV数据计算速度
     */
    public static double vectorToSpeed(double uMs, double vMs) {
        double windAbs = Math.sqrt(Math.pow(uMs, 2) + Math.pow(vMs, 2));
        return windAbs;
    }

    /**
     * UV数据计算风向
     */
    public static double vectorToDegrees(double uMs, double vMs) {
        DecimalFormat df = new DecimalFormat("#.000");
        double windAbs = Math.sqrt(Math.pow(uMs, 2) + Math.pow(vMs, 2));
        double windDirTrigTo = Math.atan2(uMs / windAbs, vMs / windAbs);
        double windDirTrigToDegrees = windDirTrigTo * 180 / Math.PI;
        double windDirTrigFromDegrees = windDirTrigToDegrees + 180;
        return Double.parseDouble(df.format(windDirTrigFromDegrees));
    }


    public static void main(String[] args) {
        double u = -3.3392;
        double v = -5.1872;
        // 测试转换函数
        double result1 = vectorToDegrees(u,v);
        double result2 = vectorToSpeed(u,v);
        System.out.println("风向: " +  result1);
        System.out.println("风速: " +  result2);
    }
}